{{include file="public/header" /}}

<!-- right content start  -->
<div class="content-right">
	<div class="content">
		<!-- form start -->
		<form class="am-form form-validation view-save" action="{{:MyUrl('admin/merchant/save')}}" method="POST"
			request-type="ajax-url" request-value="{{:MyUrl('admin/merchant/index', $params)}}">
			<legend>
				<span class="am-text-default">子商户{{if empty($data['id'])}}添加{{else /}}编辑{{/if}}</span>
				<a href="{{:MyUrl('admin/merchant/index', $params)}}"
					class="am-fr am-text-sm am-margin-top-sm am-icon-mail-reply">
					返回</a>
			</legend>
			<div class="am-form-group">
				<label>入网类型</label>
				<select name="mchnt_type" class="am-radius chosen-select" data-validation-message="请选择入网类型" required>
					{{foreach :$mertype as $v}}
					<option value="{{$v.id}}"
						{{if isset($data['mchnt_type']) and $data['mchnt_type'] eq $v['id']}}selected{{else /}}{{if !isset($data['mchnt_type']) and isset($v['checked']) and $v['checked'] eq true}}selected{{/if}}{{/if}}>
						{{$v.name}}</option>
					{{/foreach}}
				</select>
			</div>
			<div class="am-form-group">
				<label>姓名</label>
				<input type="text" name="legal_name" class="am-radius" placeholder="姓名"
					data-validation-message="输入身份证上的名字" {{if !empty($data)}} value="{{$data.legal_name}}" {{/if}} />
			</div>
			<div class="am-form-group">
				<label>身份证号</label>
				<input type="text" name="legal_idcard" class="am-radius" placeholder="身份证号"
					pattern="{{:MyConst('common_regex_id_card')}}" data-validation-message="手机号码格式错误"
					{{if !empty($data)}} value="{{$data.legal_idcard}}" {{/if}} />
			</div>
			<div class="am-form-group region-linkage" data-url="{{:MyUrl('admin/merchant/node')}}">
				<label class="block">商户所在地<span class="am-form-group-label-tips-must">必选</span></label>
				<select name="meprovince" data-next="mecity" class="am-radius chosen-select" data-placeholder="省份"
					data-validation-message="请选择省份"
					data-value="{{if isset($data['meprovince'])}}{{$data.meprovince}}{{else /}}0{{/if}}" required>
					<option value="">省份</option>
				</select>
				<select name="mecity" data-next="mecounty" class="am-radius chosen-select" data-placeholder="城市"
					data-validation-message="请选择城市"
					data-value="{{if isset($data['mecity'])}}{{$data.mecity}}{{else /}}0{{/if}}" required>
					<option value="">城市</option>
				</select>
				<select name="mecounty" class="am-radius chosen-select" data-placeholder="区/县"
					data-validation-message="请选择区/县"
					data-value="{{if isset($data['mecounty'])}}{{$data.mecounty}}{{else /}}0{{/if}}" required>
					<option value="">区/县</option>
				</select>
			</div>

			<div class="am-form-group">
				<label class="block">身份证人脸面</label>
				<ul class="plug-file-upload-view idcard_front-images-view" data-form-name="idcard_front"
					data-max-number="1" data-delete="0" data-dialog-type="images">
					{{if !empty($data)}}
					<li>
						<input type="text" name="idcard_front" value="{{$data.idcard_front}}" />
						<img src="{{:AttachmentPathViewHandle($data.idcard_front)}}" />
					</li>
					{{/if}}
				</ul>
				<div class="plug-file-upload-submit" data-view-tag="ul.idcard_front-images-view">+选择身份证人脸面</div>
			</div>
			<div class="am-form-group">
				<label class="block">身份证国徽面</label>
				<ul class="plug-file-upload-view idcard_back-images-view" data-form-name="idcard_back"
					data-max-number="1" data-delete="0" data-dialog-type="images">
					{{if !empty($data)}}
					<li>
						<input type="text" name="idcard_back" value="{{$data.idcard_back}}" />
						<img src="{{:AttachmentPathViewHandle($data.idcard_back)}}" />
					</li>
					{{/if}}
				</ul>
				<div class="plug-file-upload-submit" data-view-tag="ul.idcard_back-images-view">+选择身份证国徽面</div>
			</div>
			<div class="am-form-group">
				<label class="block">手持身份证</label>
				<ul class="plug-file-upload-view hand_idcard-images-view" data-form-name="hand_idcard"
					data-max-number="1" data-delete="0" data-dialog-type="images">
					{{if !empty($data)}}
					<li>
						<input type="text" name="hand_idcard" value="{{$data.hand_idcard}}" />
						<img src="{{:AttachmentPathViewHandle($data.hand_idcard)}}" />
					</li>
					{{/if}}
				</ul>
				<div class="plug-file-upload-submit" data-view-tag="ul.hand_idcard-images-view">+选择手持身份证照片</div>
			</div>
			<div class="am-form-group region-linkage" data-url="{{:MyUrl('admin/merchant/node')}}">
				<label class="block">开户行地址<span class="am-form-group-label-tips-must">必选</span></label>
				<select name="province" data-next="city" class="am-radius chosen-select" data-placeholder="省份"
					data-validation-message="请选择省份"
					data-value="{{if isset($data['province'])}}{{$data.province}}{{else /}}0{{/if}}" required>
					<option value="">省份</option>
				</select>
				<select name="city" data-next="county" class="am-radius chosen-select" data-placeholder="城市"
					data-validation-message="请选择城市"
					data-value="{{if isset($data['city'])}}{{$data.city}}{{else /}}0{{/if}}" required>
					<option value="">城市</option>
				</select>
				<select name="county" class="am-radius chosen-select" data-placeholder="区/县"
					data-validation-message="请选择区/县"
					data-value="{{if isset($data['county'])}}{{$data.county}}{{else /}}0{{/if}}" required>
					<option value="">区/县</option>
				</select>
			</div>
			<div class="am-form-group region-linkage">
				<label class="block">银行名称</label>
				<select name="head_bankno" id="merbankcode" data-url="{{:MyUrl('admin/merchant/bankno')}}"
					class="am-radius chosen-select" data-validation-message="请选择银行名称" required>
					{{foreach :$bankcodes as $v}}
					<option value="{{$v.code}}"
						{{if isset($data['head_bankno']) and $data['head_bankno'] eq $v['id']}}selected{{else /}}{{if !isset($data['head_bankno']) and isset($v['checked']) and $v['checked'] eq true}}selected{{/if}}{{/if}}>
						{{$v.name}}</option>
					{{/foreach}}
				</select>
				<select name="bank_code" id="zhibankcode" class="am-radius chosen-select"
					data-validation-message="请选择支行名称" required>
					<option value="">开户支行</option>
				</select>
			</div>
			<div class="am-form-group">
				<label>银行卡号</label>
				<input type="text" name="card_no" class="am-radius" placeholder="银行卡号" data-validation-message="输入银行卡号"
					{{if !empty($data)}} value="{{$data.card_no}}" {{/if}} />
			</div>
			<div class="am-form-group">
				<label>手机号码</label>
				<input type="text" name="mobile" class="am-radius" placeholder="银行预留手机号码"
					pattern="{{:MyConst('common_regex_mobile')}}" data-validation-message="手机号码格式错误"
					{{if !empty($data)}} value="{{$data.mobile}}" {{/if}} />
			</div>
			<div class="am-form-group">
				<label class="block">结算银行卡</label>
				<ul class="plug-file-upload-view settle_bankcard-images-view" data-form-name="settle_bankcard"
					data-max-number="1" data-delete="0" data-dialog-type="images">
					{{if !empty($data)}}
					<li>
						<input type="text" name="settle_bankcard" value="{{$data.settle_bankcard}}" />
						<img src="{{:AttachmentPathViewHandle($data.settle_bankcard)}}" />
					</li>
					{{/if}}
				</ul>
				<div class="plug-file-upload-submit" data-view-tag="ul.settle_bankcard-images-view">+选择结算银行卡</div>
			</div>
			<div class="am-form-group am-form-group-refreshing am-margin-top-lg am-padding-left-0">
				<input type="hidden" name="id" {{if !empty($data)}} value="{{$data.id}}" {{/if}} />
				<button type="submit" class="am-btn am-btn-primary am-radius btn-loading-example am-btn-sm am-btn-block"
					data-am-loading="{loadingText:'处理中...'}">保存</button>
			</div>
		</form>
		<!-- form end -->
	</div>
</div>
<!-- right content end  -->

<!-- footer start -->
{{include file="public/footer" /}}
<!-- footer end -->
<script type="text/javascript">
	$('#merbankcode').on('change', function () {
		var province = $('.region-linkage select[name=province] option:selected');
			city = $('.region-linkage select[name=city] option:selected');
			code = $(this).val() || null; //获取银行代码
		if (province.val() <= 0 || city.val() <= 0) {
			Prompt("请选择开户行所在省市县");
			returnfalse;
		}
		$.ajax({
			url: $("#merbankcode").attr('data-url'),
			type: 'POST',
			data: {
				"province": province.val(),
				'city': city.val(),
				'code': code
			},
			dataType: 'json',
			success: function (result) {
				console.log(JSON.stringify(result));
				if (result.code == 0) {
					var html = '';
					for (var i in result.data) {
						html += '<option value="' + i + '">' + result.data[i] + '</option>';
					} /* 下一级数据添加 */
					$("#zhibankcode").html(html).trigger('chosen:updated');
				} else {
					Prompt(result.msg);
				}
			}
		});
	});
</script>